﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chowpoo.Sql;
using CourseSystem.Core.Entities;
using CourseSystem.Core.SqlServerDAL;

namespace CourseSystem.Core.BLL
{
    public class ExamBLL : CommonBLL<ExamInfo, ExamDAL>
    {
        public static IQueryable<ExamInfo> GetList(int collegeId, int departId, int subjectId, int classId, int yearId)
        {
            var re = GetList();
            if (yearId != 0)
                re = re.Where(o => o.YearId == yearId);
            if (collegeId != 0)
                re = re.Where(o => o.ClassInfo.SubjectInfo.DepartmentInfo.CollegeId == collegeId);
            if (departId != 0)
                re = re.Where(o => o.ClassInfo.SubjectInfo.DepartId == departId);
            if (subjectId != 0)
                re = re.Where(o => o.ClassInfo.SubjectId == subjectId);
            if (classId != 0)
                re = re.Where(o => o.ClassId == classId);
            return re;
        }

        public static ExamInfo Get(int value)
        {
            using (var dal = new ExamDAL(Settings.ConnectionName))
            {
                var re = dal.SelectSingle(o => o.Id == value);
                return re;
            }
        }

        public static bool Del(int id)
        {
            using (var dal = new ExamDAL())
            {
                return dal.Delete(o => o.Id == id) != null;
            }
        }
    }
}
